package com.itheima.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.constant.RedisConstant;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import com.itheima.ulits.DateUtils;
import com.itheima.ulits.QiniuUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.List;
import java.util.Set;

/**
 * 定时清理垃圾图片
 *
 * @author ：zengjie
 * @date ：2020/11/11
 */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;
    /**
     * 清楚redis垃圾图片
     */
    public void clearImg() {
        //1.Redis 中key1集合-key2集合得到差集（垃圾图片名称集合）
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        System.out.println("你好帅");
        if (sdiff != null && sdiff.size() > 0) {
            for (String filename : sdiff) {
                //2.调用七牛云删除图片接口
                QiniuUtils.deleteFileFromQiniu(filename);
                //3.删除redis中key1集合中的垃圾图片名称
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, filename);
            }
        }
    }
}
